package it.xiuxian.homepage.activity

import android.os.Build
import android.view.Gravity
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import it.xiuxian.homepage.R
import it.xiuxian.homepage.bean.GongXian
import it.xiuxian.homepage.bean.MonGongXianBean
import it.xiuxian.homepage.databinding.HomepageGongxianBinding
import it.xiuxian.homepage.fragment.PaiHangBangFragment
import it.xiuxian.homepage.fragment.ZiXunFragment
import it.xiuxian.homepage.presenter.PaiHangBangActivityPresenter
import it.xiuxian.lib.base.App
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.lib.utils.DensityUtil
import it.xiuxian.lib.utils.HeySlidingTabLayout
import it.xiuxian.lib.utils.ImageUtil
import it.xiuxian.lib.utils.adapter.SlimAdapter
import it.xiuxian.lib.utils.adapter.SlimInjector
import it.xiuxian.lib.utils.adapter.injector.IViewInjector
import it.xiuxian.swindle.adapter.MyFragmentAdapter
import java.util.ArrayList


@Route(path = ArouterAddress.PAIHANGBANGACTIVITY)
class PaiHangBangActivity:BaseActivity<PaiHangBangActivityPresenter>() {

   lateinit var binding:HomepageGongxianBinding
    lateinit var fragments: ArrayList<Fragment>
    @JvmField
    @Autowired
    var flag:String? = null
    override val layoutId: Int
        get() = R.layout.homepage_gongxian
    override val presenter: PaiHangBangActivityPresenter
        get() = PaiHangBangActivityPresenter()
    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun initView() {
        //super.initView()
        ARouter.getInstance().inject(this)
       binding = getViewDataBinding<HomepageGongxianBinding>()
        initTab()

    }
        fun initTab(){
            fragments = ArrayList()
            val titles:Array<String> = arrayOf("月榜","总榜")
            fragments.add(ARouter.getInstance().build(ArouterAddress.PAIHANGBANGFRAGMENT).withString("flag","1").navigation() as PaiHangBangFragment)
            fragments.add(ARouter.getInstance().build(ArouterAddress.PAIHANGBANGFRAGMENT).withString("flag","2").navigation() as PaiHangBangFragment)
            binding.viewpager.adapter= MyFragmentAdapter(supportFragmentManager,fragments)
            binding.tab.setViewPager(binding.viewpager,titles)
            binding.tab.currentTab = 0
            binding.tab.isTabSpaceEqual = false
            binding.tab.setIndicatorWidthEqualTitle(false)
            binding.tab.textsize = 50f
            binding.tab.textBold = 2
            binding.tab.setUnderlineGravity(Gravity.BOTTOM)
            binding.tab.indicatorColor =resources.getColor(R.color.red_1)
            binding.tab.indicatorWidth = 20f
            binding.tab.textSelectColor = resources.getColor(R.color.red_1)
            binding.tab.textUnselectColor=resources.getColor(R.color.libTextBlack)
            binding.tab.setOnTabSelectListener(object : HeySlidingTabLayout.OnTabSelectListener{
                override fun onTabSelect(position: Int): Boolean {
                    binding.viewpager.currentItem = position
                    return false
                }

                override fun onTabReselect(position: Int) {

                }

            })
        }
    override fun initEvent() {
        binding.cons.setOnClickListener { finish() }
        //binding.cons.setPadding(0,DensityUtil.px2dip(App.INSTANCE!!.applicationContext),0,0)
        (binding.cons.layoutParams as LinearLayout.LayoutParams).setMargins(0,
            DensityUtil.getStatusPix(App.INSTANCE.applicationContext)+5,0,0)
    }


}